//
//  KindGoodsView.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/4.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "KindGoodsView.h"
#import "KindGoodsViewCell.h"
#import "ShopGoodsKindsModel.h"

@implementation KindGoodsView


- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5f];
       //[self setTitArray:_titArray];
        
    }
    return self;
}


-(void)setTitArray:(NSArray *)titArray {
    _titArray = titArray;
    [self configureView];
}

- (void)configureView {
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kView_Height - 50 *_titArray.count,kView_Width , 50 *_titArray.count)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.showsVerticalScrollIndicator = NO;
    _tableView.showsHorizontalScrollIndicator = NO;
    _tableView.separatorStyle = kSpNone;
    _tableView.backgroundColor = KShouYeBg;
    [self addSubview:_tableView];
    [self.tableView registerNib:[UINib nibWithNibName:@"KindGoodsViewCell" bundle:nil] forCellReuseIdentifier:@"KindGoodsViewCell"];
    
    UIButton *remoBtn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    remoBtn.frame = CGRectMake(0, 0, kView_Width, kView_Height - CGRectGetHeight(_tableView.frame));
    [remoBtn  setBackgroundColor:[UIColor clearColor]];
    [remoBtn addTarget:self action:@selector(remoKindGoodsView:) forControlEvents:(UIControlEventTouchUpInside)];
    [self addSubview:remoBtn];

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return  _titArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 5;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kView_Width, 5)];
    view.backgroundColor = KShouYeBg;
    
    return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    KindGoodsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"KindGoodsViewCell"];
    ShopGoodsKindsModel *model =self.titArray[indexPath.row];
    cell.selectionStyle = kSeNone;
    cell.titlLB.text = model.name;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
     ShopGoodsKindsModel *model =self.titArray[indexPath.row];
    if(self.delegate && [self.delegate respondsToSelector:@selector(setlectKindGoodIndepath:titleStr:)])
    {
        [self.delegate setlectKindGoodIndepath:indexPath titleStr:model.Id];
    }
}

//改变视图位置
- (void)remoKindGoodsView:(UIButton *)sender {
    if(self.delegate && [self.delegate respondsToSelector:@selector(changeKindGoodsFrame:)])
    {
        [self.delegate changeKindGoodsFrame:sender];
    }
}



@end
